
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>DataSchema.Text</title>

<style type="text/css">
/*margin and padding on body element
  can introduce errors in determining
  element position and are not recommended;
  we turn them off as a foundation for YUI
  CSS treatments. */
body {
	margin:0;
	padding:0;
}
</style>

<link type="text/css" rel="stylesheet" href="../../build/cssfonts/fonts-min.css" />
<script type="text/javascript" src="../../build/yui/yui-min.js"></script>


<!--begin custom header content for this example-->
<style type="text/css">
/* custom styles for this example */
#demo .output {margin-bottom:1em; padding:10px; border:1px solid #D9D9D9;}
</style>

<!--end custom header content for this example-->

</head>

<body class="yui3-skin-sam  yui-skin-sam">

<h1>DataSchema.Text</h1>

<div class="exampleIntro">
	DataSource.Text normalizes delimited text data against a given schema into an object with known properties.
			
</div>

<!--BEGIN SOURCE CODE FOR EXAMPLE =============================== -->

<form id="demo">
    <h6>Data</h6>
    <pre>
notebooks, 100, spiral-bound
pencils, 300, #2 with erasers
pens, 500, blue ink
    </pre>
    
    <h6>Schema</h6>
    <pre>
{
    resultDelimiter: "\n",
    fieldDelimiter: ",",
    resultFields: [{key:"product"}, {key:"quantity"}, {key:"detail"}]
}
    </pre>

    <h6>Normalized data</h6>
    <input type="button" id="demo_apply" value="Apply schema =>">
    <div id="demo_output" class="output"></div>
</form>

<script type="text/javascript">
YUI().use("dump", "node", "dataschema-text", function (Y) {
    Y.on("click", function(e){
        var data_in = "notebooks, 100, spiral-bound\npencils, 300, #2 with erasers\npens, 500, blue ink\n",
            schema = {
                resultDelimiter: "\n",
                fieldDelimiter: ",",
                resultFields: [{key:"product"}, {key:"quantity"}, {key:"detail"}] // Or simply: ["product", "quantity", "detail"]
            };
        Y.one("#demo_output").setContent(Y.dump(Y.DataSchema.Text.apply(schema, data_in)));
    }, "#demo_apply");
});
</script>

<!--END SOURCE CODE FOR EXAMPLE =============================== -->

</body>
</html>
